<script src="../../api/system/generic.js"></script>
<template>
  <div class="container">
    <div class="middle">
      <el-table ref="multipleTable" :data="tableData" stripe tooltip-effect="dark" style="width: 100%">
        <el-table-column label="脚本id" prop="taskId"></el-table-column>
        <el-table-column label="脚本名称" prop="taskName"></el-table-column>
        <el-table-column label="描述" prop="taskNote"></el-table-column>
        <el-table-column label="脚本路径" prop="scriptPath"/>
        <el-table-column label="cron表达式" prop="cron"></el-table-column>
        <el-table-column label="状态" prop="state">
          <template slot-scope="scope">
            <span>{{ getState(scope.row.state) }}</span>
          </template>
        </el-table-column>
        <el-table-column label="日志">
          <template slot-scope="{row:{total,score}}">
            {{`此次脚本共分析${total}条数据，其中有${score}条数据为有用数据`}}
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
  window._interceptConfig = {
    collection: true, //整体开关
    click: true, //页面点击事件信息采集开关
    page: true, //页面跳转加载事件信息采集开关
    error: true, //异常信息采集开关
    http: true, //通讯信息采集开关
    name: "jyzdhywxxxtsdfx_n_prd.mart-ui-ds", //系统编号，被采集信息的系统名称。前端简称
    url: " http://apm.sd.sgcc.com.cn:19411/api/v2/spansWeb"//数据上报服务地址，根据实际情况输入
  };
</script>
<!-- src -->
<script src=" http://25.41.37.249:19411/assets/js/intercept.min.js " async></script>
<script>
  import { queryScriptApp ,updateScriptAppById } from "@/api/system/analysisview"
  export default {
    name: 'Logscript',
    data() {
      return {
        // 表格数据
        tableData: null,
        // 功能编号
        model: 12
      }
    },
    methods: {
      // 加载数据
      initData() {
        queryScriptApp(this.model).then(response => {
          this.tableData = response.data
        })
      },

      // 返回状态
      getState(code) {
        if (code === '0') {
          return '正常'
        } else if (code === '1') {
          return '正在执行'
        }
      },
      // 执行
      check(id,st) {
        let text = ''
        if(st === 0){
          text = '取消执行'
        }else {
          text = "立即执行"
        }

        this.$confirm('要'+ text +'此脚本吗?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          if(st === 0){
            this.$message({
              type: 'success',
              message: '脚本'+id+text
            })
          }else {
            this.$message({
              type: 'success',
              message: '脚本'+id+text+"请在脚本运行时间结束后前往日志任务深度分析预警查看"
            })


          }
          updateScriptAppById(id,st).then(response => {
            //回显
            this.initData()
          })


        })
      },
    },
    mounted() {
      this.initData()
    }
  }

</script>

<style>
  .middle {
    margin: 10px;
    width: 100%;
  }
</style>
